package org.example;

import org.example.entity.CustomerInfo;
import org.example.entity.CustomerOrder;
import org.example.entity.CustomerRepayPlan;
import org.example.generator.DataGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.time.LocalDate;
import java.util.List;

/**
 * 测试复杂数据生成逻辑
 */
@SpringBootApplication
public class TestComplexDataGeneration {
    
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(TestComplexDataGeneration.class, args);
        DataGenerator dataGenerator = context.getBean(DataGenerator.class);
        
        System.out.println("=== 测试复杂数据生成逻辑 ===");
        
        // 生成测试数据
        LocalDate testDate = LocalDate.of(2023, 7, 15);
        CustomerInfo customer = dataGenerator.generateCustomerInfo(testDate);
        CustomerOrder order = dataGenerator.generateCustomerOrder(customer, testDate, "浩瀚小贷");
        List<CustomerRepayPlan> plans = dataGenerator.generateRepayPlan(order);
        
        // 输出结果
        System.out.println("客户信息:");
        System.out.println("  ID: " + customer.getId());
        System.out.println("  姓名: " + customer.getPlName());
        System.out.println("  性别: " + customer.getGender());
        System.out.println("  创建时间: " + customer.getCreatedTime());
        
        System.out.println("\n订单信息:");
        System.out.println("  订单号: " + order.getOrderNo());
        System.out.println("  贷款金额: " + order.getLoanAmount());
        System.out.println("  产品名称: " + order.getProductName());
        System.out.println("  订单状态: " + order.getStatus());
        System.out.println("  结清日期: " + order.getSettleDate());
        System.out.println("  剩余金额: " + order.getRemainPayAmount());
        
        System.out.println("\n还款计划:");
        for (CustomerRepayPlan plan : plans) {
            System.out.println("  期数: " + plan.getBillTenor() + 
                             ", 应还日期: " + plan.getDueDate() + 
                             ", 状态: " + plan.getRepayStatus() + 
                             ", 实际还款日期: " + plan.getActualRepayDate());
        }
        
        // 统计各种状态的数量
        long settledCount = plans.stream().filter(p -> "已结清".equals(p.getRepayStatus())).count();
        long overdueCount = plans.stream().filter(p -> p.getRepayStatus().contains("逾期")).count();
        long notDueCount = plans.stream().filter(p -> "未到期".equals(p.getRepayStatus())).count();
        
        System.out.println("\n统计信息:");
        System.out.println("  总期数: " + plans.size());
        System.out.println("  已结清: " + settledCount);
        System.out.println("  逾期: " + overdueCount);
        System.out.println("  未到期: " + notDueCount);
        
        context.close();
    }
}






